package com.sjb.sixteen_journey_backend.controller;


import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.ShareThing;
import com.sjb.sixteen_journey_backend.service.IShareThingService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的爆料表
 * @author jcz
 * @since 2024-07-14
 */
@RestController
@RequestMapping("/share-thing")
public class ShareThingController {
    @Autowired
    private IShareThingService shareThingService;

    /**
     * 添加爆料
     * @param shareThing
     * @return
     */
    @PostMapping("/addShareThing")
    public R addShareThing(@RequestBody @Valid ShareThing shareThing) {
        return shareThingService.addShareThing(shareThing);
    }
//    @PostMapping("/addShareThing")
//    public R addShareThing(@RequestBody ShareThing shareThing, @RequestParam("image") ArrayList<MultipartFile> images) {
//        return shareThingService.addShareThing(shareThing,images);
//    }

    /**
     * 获取所有'爆料'
     *
     * @return
     */
    @GetMapping("/getAllShareThing")
    public R<List<ShareThing>> getAllShareThing() {
        return shareThingService.getAllShareThing();
    }

    /**
     * 根据爆料id获取'爆料'
     * @param shareThingId
     * @return
     */
    @GetMapping("/getShareThingById/{shareThingId}")
    public R<ShareThing> getShareThingById(@PathVariable("shareThingId") Integer shareThingId) {
        return shareThingService.getShareThingById(shareThingId,true);
    }

    /**
     * 获取用户爆料
     * @return
     */
    @GetMapping("/getShareThingByUserId")
    public R<List<ShareThing>> getShareThingByUserId() {
        return shareThingService.getAllMyTimeByUserId();
    }


    /**
     * 删除用户的一篇爆料
     * @param id
     * @return
     */
    @DeleteMapping("/deleteShareThingById/{id}")
    public R deleteShareThingById(@PathVariable("id") Integer id ) {
        return shareThingService.deleteShareThingById(id);
    }


}
